home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / NextEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.8 KB  |  79 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <clib/extras_protos.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8.  
  9. /****** extras.lib/db_NextEntry ******************************************
  10. *
  11. *   NAME
  12. *       db_NextEntry - Find the next entry in a database file.
  13. *
  14. *   SYNOPSIS
  15. *       error = db_NextEntry(File, EntryName, Buffer, BufferSize)
  16. *       
  17. *       LONG db_NextEntry(BPTR, STRPTR, STRPTR, ULONG);
  18. *
  19. *   FUNCTION
  20. *       Seeks for the next entry in a database file.
  21. *
  22. *   INPUTS
  23. *       File - AmigaDos file handle.
  24. *       EntryName - the name of the entry, usually "ENTRY".
  25. *              case is insignificant.
  26. *       Buffer - a buffer for reading data from a file.
  27. *       BufferSize - the size of the buffer.
  28. *
  29. *   RESULT
  30. *       returns 0 on failure.  on success the file is positioned
  31. *       inside the entry.
  32. *
  33. *   EXAMPLE
  34. *
  35. *   NOTES
  36. *       This function is mainly used for other lib functions
  37. *
  38. *   BUGS
  39. *
  40. *   SEE ALSO
  41. *
  42. ******************************************************************************
  43. *
  44. */
  45.  
  46.  
  47. LONG db_NextEntry(BPTR File, STRPTR EntryName, STRPTR Buffer, ULONG BufferSize)
  48. {
  49.   while(FGets(File,Buffer,BufferSize))
  50.   {
  51.     Strip(Buffer);
  52.     if(stricmp(Buffer,EntryName)==0)
  53.     { /* found "ENTRY" */
  54.       if(FGets(File,Buffer,BufferSize))
  55.       { /* Now confirm that next line is "{" */
  56.         Strip(Buffer);
  57.         if(strcmp(Buffer,(STRPTR)"{")==0)
  58.         { /* next line is "{" */
  59.           return(1);
  60.         }
  61.       }
  62.       /* else format error */
  63.       return(0);
  64.     }
  65.     else
  66.     {
  67.       if(strcmp(Buffer,(STRPTR)"{")==0)
  68.       {
  69.         if(!FindLine(File,(STRPTR)"}",Buffer,BufferSize))
  70.         { /* format error, "{" missing matching "}"*/
  71.           return(0);
  72.         }
  73.       }
  74.     }  
  75.   } /* EOF or other error */
  76.   return(0);
  77. }
  78.  
  79.